package com.morgan.storageperlib.saf.handler

import android.content.Intent
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.morgan.storageperlib.entity.BaseActivityResultHandler

/**
 *description：通过SAF打开文件夹，回调ActivityResult
 *<br>author：caowugao
 *<br>time：2021/3/5 0005 18:32
 */
open class OpenOriginalFolderHandler(act : AppCompatActivity, contract : ActivityResultContract<Intent, ActivityResult> = ActivityResultContracts.StartActivityForResult(), callback : ActivityResultCallback<ActivityResult>) : BaseActivityResultHandler(act, contract, callback){

    fun launch() {
        try {
            val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
            launcher.launch(intent)
        } catch (e : Throwable) {
            e.printStackTrace()
        }
    }
}